#pragma once
#include "Iresource.h"
 
#define  RESOURCE_TYPE_RENDEERTOTEXTURE 10
 
class WPENGIN_API CRenderToTexture :public ITexture
{
public:
	CRenderToTexture( const TCHAR * resName, DWORD width ,DWORD height, D3DFORMAT fmt=D3DFORMAT::D3DFMT_A8R8G8B8);
 
	void Render(D3DXMATRIX * matView,D3DXMATRIX * matProj,int n, ...);
	void  RenderWithBeginScene(D3DXMATRIX * pmatView,D3DXMATRIX *pmatProj, int n , ... );

   void  RenderWithBeginScene( IRenderable * pRenderable ,D3DXMATRIX * pmatView=NULL,D3DXMATRIX *pmatProj=NULL) ;
	  
	void SetRenderTarget();
	void UnSetRenderSetRender();

 
	 void SaveToFile(LPCTSTR strFile);
	virtual  void OnD3D9LostDevice();
	virtual HRESULT   OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice);


	
private:
	 D3DFORMAT m_fmt;
	LPD3DXRENDERTOSURFACE m_pRenderToSurface;
    LPDIRECT3DSURFACE9  m_TextureSurface ;
	LPDIRECT3DSURFACE9  m_pDepthSurface;

	LPDIRECT3DSURFACE9  m_pOldSureface;
	LPDIRECT3DSURFACE9 m_pOldDepthSurface;

#pragma region UnitTest
#ifdef _DEBUG


	class GameUnitTest :  public ITerminate ,public IInitialize,IRenderable
	{
		void  OnTerminate( void );
		HRESULT  OnInitialize( void );
		virtual void OnD3D9FrameRender( float fElapsedTime );

       CSprite  * m_pSprite;
	   CFileTexture *  m_pTexture;
	    D3DXMATRIX m_matProj,m_matWorld,m_matView;
	   CRenderToTexture * pRenderToTexture;
	   
	};
public:
	static void UnitTest();

#endif // _DEBUG
#pragma endregion UnitTest

 





};